package com.baizhi.service.impl;

import com.baizhi.annotation.LogAnnotation;
import com.baizhi.dao.AdminDao;
import com.baizhi.entity.Admin;
import com.baizhi.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 野马 on 2019/6/14.
 */
@Service
public class AdminServiceImpl implements AdminService{

    @Autowired
    private AdminDao adminDao;

    @Override
    public Admin login(String username, String password) {
        Admin admin = adminDao.login(username, password);
        return admin;
    }

    @Override
    public void updatePassword(String newPassword, int id) {
        adminDao.updatePassword(newPassword, id);
    }

    @Override
    public void insertAdmin(Admin admin) {
        adminDao.insertAdmin(admin);
    }

    @Override
    public void deleteAdmin(int id) {
        adminDao.deleteAdmin(id);
    }

    @Override
    public void updateAdmin(Admin admin) {
        adminDao.updateAdmin(admin);
    }

    @Override
    public Map selectList(int page,int rows) {
        int start = (page-1)*rows;
        int pageSize = rows;

        int countAdmin = adminDao.countAdmin();
        List<Admin> adminList = adminDao.selectList(start, pageSize);


        Map map = new HashMap();
        map.put("total",countAdmin);
        map.put("rows",adminList);


        return map;
    }
}
